package com.zhang.learn.regex;

import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式的简单学习
 * @author zhanghaolian
 * @date 2021/6/13 21:47
 */
public class RegexpLearn {
    @Test
    public void simpleTest() {
        String context = "I have a dream";

        String pattern = ".*dream.*";

        boolean isMatch = Pattern.matches(pattern, context);

        System.out.println(isMatch ? "匹配成功" : "匹配失败");
    }

    @Test
    public void test2() {
        String content = "123456789";

        String regExp = "(\\d\\d)(\\d\\d)";

        Pattern pattern = Pattern.compile(regExp);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            System.out.println(matcher.group(1));
        }
    }

}
